local SleepDeck = GS:addState('SleepDeck')
function SleepDeck:enterState()
	clearLoveCallbacks()
	print("entering sleep deck state")

	local lm = map[1]

	

	

	map_items = {}


	local mGrid = Grid(lm.layout)
	local mFinder = Pathfinder(mGrid, 'JPS', floor_tile)
	mFinder:setMode('ORTHOGONAL')

	


	if lm.visited == false then
		map_x = lm.map_x
		map_y = lm.map_y

		pX = map_x+view_center_x
		pY = map_y+view_center_y

		-- map state transitions

		local mtpts = m_get_exits(lm)

		--MapTran:multi(mtpts)

		for i = 1, #mtpts do

			Elevator:new(mtpts[i].x, mtpts[i].y, mtpts[i].dest)

		end


		local help1 = SoundEvent:new("help us", 9, 7, help_us_aud)

		local pp = {
			{x = 4, y = 11},
			{x = 14, y = 8},
			{x = 26, y = 12},
			{x = 25, y = 30},
			{x = 4, y = 30},

		}

		local enmy = Enemy:new("green_bug", 14, 28, green_bug_img, mGrid, mFinder, lm.layout, true, pp )
		enmy:random_patrol(8)
		local enmy2 = Enemy:new("frog", 14, 28, frog_img, mGrid, mFinder, lm.layout, true, pp )
		enmy2:random_patrol(12)
		local enmy3 = Enemy:new("preacher", 14, 28, preacher_bot_img, mGrid, mFinder, lm.layout, true, pp )
		enmy3:random_patrol(16)


		player.x = lm.features.start.x*(tile_size)
		player.y = lm.features.start.y*(tile_size)

		local tablet = Tablet:new("tablet 001", tablet_img,
			9, 4, 0, tablet_text[1])

		local batt = Battery:new("batt 001", 22, 8, 0, nil, 500)

		for	i = 1, 3 do

			local ft = SleepPod:new("ft "..i, htube_imgs[i], 4, 3+i, 0)

			if i == 1 then
				ft:set_text("Your open hypersleep tube")
			elseif i == 2 then
				ft:set_text("Captain Reginald Davis is still in hypersleep.")
			elseif i == 3 then
				ft:set_text("First Officer Aluicius Plank is still in hypersleep.")
			end

		end

		Item:spawn_items(lm.items)

		Scourge:walls(lm.scourge, lm.layout)
		Scourge:generate(lm.scourge)

		Fog:multi(lm.layout)

		lm.visited = true

		local msg_opt = {
			name = player.name,

		}

		msgs[#msgs+1] = _navi:new('You awaken inside your hypersleep tube.', msg_opt)

		if game_options.moody  == true then

		else
			light_scene()
		end

	else
		map_items = SleepDeck.map_items
		features = SleepDeck.features
		events = SleepDeck.events
		enemies = SleepDeck.enemies 
		fog = SleepDeck.fog
		map_x = SleepDeck.last_map_x
		map_y = SleepDeck.last_map_y
		pX = map_x+view_center_x
		pY = map_y+view_center_y

	end



	draw_map(lm.layout)



	con_count = 0
	light_count = 0
	m_count = player.fire_rate*60
	function love.update(dt)

		arc.check_keys(dt)


		global_updates(dt)

		p_update(dt)
		update_animations(dt, anims)



		light_features()

		Event:update(dt)
		Enemy:update(dt)
		Item:update(dt)

		update_proj(dt, projectiles, lm.layout)
		mouse_update(dt)

		con_count = update_con(con_count)
		light_count = p_light_energy(light_count)



	end

	function love.draw()





		love.graphics.setColor(66,66,66)
		love.graphics.draw(tileset_batch)
		Event:draw_all()
		love.graphics.setColor(255,255,255)

		--light_tiles(lm.layout)


		draw_group(features)

		draw_proj(projectiles)
		draw_animations(anims)

		Item:draw_all()

		draw_player(player)

		Enemy:draw_all()

		Fog:draw()

		draw_hud()

		msg_queue_draw() -- must be before arc.clear_key()

		arc.clear_key()



		draw_mouse()

	end



	function love.keypressed(key, unicode)

		arc.set_key(key)

		p_control(key,unicode, lm)

	end

	function love.mousepressed(x, y, button)

		mouse_click(x, y, button)

	end

end

function SleepDeck:exitState()

	print("exiting sleep deck state")

	player.last_state = 'SleepDeck'

	SleepDeck.map_items = map_items
	SleepDeck.features = features
	SleepDeck.events = events
	SleepDeck.enemies = enemies
	SleepDeck.fog = fog
	SleepDeck.last_map_x = map_x
	SleepDeck.last_map_y = map_y

	map_items = {}
	features = {}
	events = {}
	enemies = {}
	fog = {}


	clean_msg()


end

